package com.hmyd.hmyd_android.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.AppBasic;
import com.hmyd.hmyd_android.ui.InvestmentListActivity;

public class InvestmentSuccessDialog extends Dialog implements
		android.view.View.OnClickListener {
	
	private TextView mTip;

	private Button mContinueInvestment;
	private Button mHistoryInvestment;
	
	private String mStringTip;
	
	private Activity mContent;

	public InvestmentSuccessDialog(Context context) {
		super(context);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

	}

	public InvestmentSuccessDialog(Activity context, int theme, String stringTip) {
		super(context, theme);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		mContent = context;
		mStringTip = stringTip;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_investment_success);

		mTip = (TextView) findViewById(R.id.tip);
		mTip.setText(mStringTip);
		
		mContinueInvestment = (Button) findViewById(R.id.continue_investment);
		mContinueInvestment.setOnClickListener(this);
		mHistoryInvestment = (Button) findViewById(R.id.history_investment);
		mHistoryInvestment.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.continue_investment:
			cancel();
			break;
		case R.id.history_investment:
			String selectionString = "1";
			mContent.startActivity(InvestmentListActivity.getIntent(mContent, selectionString));
			AppBasic.getInstance().finishActivity(mContent);
			cancel();
			break;
		default:
			break;
		}

	}
	
	@SuppressWarnings("static-access")
	@Override
	public void cancel() {
		super.cancel();
		mContent.setResult(mContent.RESULT_OK);
		mContent.finish();
		
		Intent intent = new Intent("RELOAD");
		mContent.sendBroadcast(intent);
	}

}
